package cn.batchDelete;

import cn.GetPath.accessPath;
import cn.dto.BizConstant;
import cn.dto.Equipments;
import cn.hutool.http.HttpRequest;
import cn.uploading.ExcelApp;
import cn.utils.AnalysisExcel;
import cn.utils.GuideTable;
import cn.utils.ReadTxt;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class batchD {

    private static Logger log4j = Logger.getLogger(batchD.class);

    private static final AtomicInteger deviceCount = new AtomicInteger();

    public static void main(String[] args) throws IOException {


        BizConstant bizConstant = ReadTxt.readFile(accessPath.getTxt());
        String upl_url = bizConstant.getUPL_URL();

        AnalysisExcel analysisExcel = new AnalysisExcel();

        ArrayList<cn.zyh.dto.BasicInformation> basicInformations = analysisExcel.ToAnalysisExcel(accessPath.getXls());
        basicInformations.forEach(e -> {
            Equipments equipments = new Equipments(e.getSensorId(), e.getSensorType(), e.getDataCode());

            String stuString = JSONObject.toJSONString(equipments);
            System.out.println(stuString);

            String resp = HttpRequest.delete("http:" + upl_url + ":8000/api-projectdatamanage/equipmentsync").body("{\"equipments\":[" + stuString + "]}").header("Authenticator", GuideTable.getSessionId(bizConstant)).execute().body();
            deviceCount.incrementAndGet();
            log4j.info(resp);
        });
        log4j.info("删除个数"+deviceCount);


    }
}
